package com.ruoyi.web.controller.mes;


import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.kt.mes.domain.StorageOutRecord;
import com.kt.mes.service.IStorageOutRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库记录Controller
 *
 * @author lzc
 * @date 2021-01-27
 */
@RestController
@RequestMapping("/mes/CkRecord")
public class StorageOutRecordController extends BaseController
{
    @Autowired
    private IStorageOutRecordService storageOutRecordService;

    /**
     * 查询出库记录列表
     */
    @PreAuthorize("@ss.hasPermi('mes:CkRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(StorageOutRecord storageOutRecord)
    {
        startPage();
        List<StorageOutRecord> list = storageOutRecordService.selectStorageOutRecordList(storageOutRecord);
        return getDataTable(list);
    }

    /**
     * 导出出库记录列表
     */
    @PreAuthorize("@ss.hasPermi('mes:CkRecord:export')")
    @Log(title = "出库记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StorageOutRecord storageOutRecord)
    {
        List<StorageOutRecord> list = storageOutRecordService.selectStorageOutRecordList(storageOutRecord);
        ExcelUtil<StorageOutRecord> util = new ExcelUtil<StorageOutRecord>(StorageOutRecord.class);
        return util.exportExcel(list, "CkRecord");
    }

    /**
     * 获取出库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:CkRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(storageOutRecordService.selectStorageOutRecordById(id));
    }

    /**
     * 新增出库记录
     */
    @PreAuthorize("@ss.hasPermi('mes:CkRecord:add')")
    @Log(title = "出库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StorageOutRecord storageOutRecord)
    {
        return toAjax(storageOutRecordService.insertStorageOutRecord(storageOutRecord));
    }

    /**
     * 修改出库记录
     */
    @PreAuthorize("@ss.hasPermi('mes:CkRecord:edit')")
    @Log(title = "出库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StorageOutRecord storageOutRecord)
    {
        return toAjax(storageOutRecordService.updateStorageOutRecord(storageOutRecord));
    }

    /**
     * 删除出库记录
     */
    @PreAuthorize("@ss.hasPermi('mes:CkRecord:remove')")
    @Log(title = "出库记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storageOutRecordService.deleteStorageOutRecordByIds(ids));
    }
}
